package com.tanhua.manage.controller;

import com.tanhua.manage.service.UserManageService;
import com.tanhua.manage.vo.Pager;
import com.tanhua.sso.pojo.User;
import com.tanhua.sso.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@RequestMapping("manage")
public class UserManageController {
    @Autowired
    private UserManageService userManageService;

    @Autowired
    private UserService userService;

    @GetMapping("users")
    public ResponseEntity<Pager> queryUsers(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                     @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                     String token) {
        try {
            User user = userService.queryUserByToken(token);
            if (user!=null){
                Pager pager = this.userManageService.queryUsers(page, pageSize);
                return ResponseEntity.ok(pager) ;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }
}
